<template>
	<el-alert
		title="系统提示: 请勿随意泄露个人信息及密码，防止出现账号盗用问题"
		type="warning" show-icon style="margin-bottom: 15px;"/>

	<el-card shadow="never" header="个人信息">
		<el-form :rules="rules"  ref="dialogForm"  :model="form" label-width="120px" style="margin-top:20px;">
			<el-form-item label="登陆账号">
				<el-input v-model="form.username" disabled></el-input>
				<div class="el-form-item-msg">账号信息用于登录，系统不允许修改</div>
			</el-form-item>
			<el-form-item label="用户昵称" prop="nickname">
				<el-input v-model="form.nickname"></el-input>
			</el-form-item>
			<el-form-item label="性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别" prop="sex">
				<el-select v-model="form.sex" placeholder="请选择">
					<el-option label="保密" :value="3"></el-option>
					<el-option label="男" :value="1"></el-option>
					<el-option label="女" :value="2"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机">
				<el-input v-model="form.phone"></el-input>
			</el-form-item>
			<el-form-item label="邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱">
				<el-input v-model="form.email"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save" :loading="isSaveing">保存</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
export default {
	data() {
		return {
			isSaveing: false,
			form: {
				username: "",
				nickname: "",
				sex: "3",
				phone: "",
				email: ""
			},
			rules: {
				nickname: [
					{required: true, message: '请输入用户昵称'}
				],
				sex: [
					{required: true, message: '请选择性别'}
				]
			}
		}
	},
	mounted() {
		this.init();
	},
	methods: {

		async init() {
			let res = await this.$API.home.personal.getLoginUserInfo.get();
			this.form.username = res.data.username;
			this.form.nickname = res.data.nickname;
			this.form.sex = res.data.sex;
			this.form.phone = res.data.phone;
			this.form.email = res.data.email;
		},

		async save() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res = await this.$API.home.personal.edit.put(this.form);
					if (res.status == 200) {
						this.$message.success("操作成功")
					}
					this.isSaveing = false;
				}
			})
		}

	}
}
</script>

<style>
</style>
